#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
char* countAndSay(int n)
{
    char* ret = malloc(sizeof(char) * 100000);
    assert(ret);
    char* cur = ret;
    char* prev = malloc(sizeof(char) * 100000);
    int count = 1;
    for (int i = 0; i < n; i++)
    {
        if (i == 0)
        {
            *cur++ = '1';
            *cur = '\0';
        }
        else if (i == 1)
        {
            *cur++ = '1';
            *cur++ = '1';
            *cur = '\0';
        }
        else
        {
            int len = strlen(ret);
            for (int i = 0; i < len; i++)
            {
                prev[i] = ret[i];
            }
            prev[len] = '\0';
            while (len > 0)
            {
                char mid = *prev;
                while (*prev == *(prev + 1))
                {
                    prev++;
                    count++;
                    len--;
                    if (len < 2)
                        break;
                }
                len--;
                *cur++ = count + 48;
                *cur++ = mid;
                prev++;
                count = 1;
            }
        }
        *cur = '\0';
        cur = ret;
    }
    return ret;
}
int main()
{
    printf("%s", countAndSay(4));
    return 0;
}